#ifndef commK_h
#define commK_h

/**
 * @defgroup nxbot_commK COMMK Library
 * @ingroup nxbot_high_level
 * @code #include <commK.h> @endcode
 * @brief Communication library for implementing the serial protocol used for communication with the Linux-embbeded system of NXBot. 
 *
 * This module relies on the UART library from the @ref nxbot_low_level. It implements a fashion-like khepera protocol. Not all the commands
 * are compatible. The idea behind using this protocol was the facility for debugging the code using a simple serial connection and ASCII-like 
 * command and data. This module implements only the Data Link Layer. The application Layer is implemented in the @ref nxbot_commTask module.
 * 
 */
 
/**@{*/

/**
 * @brief Max. Size of data in %stream.
 */
#ifndef COMMK_DATASIZE
#define COMMK_DATASIZE 40
#endif

/**
 * @brief Number of extra fields included in the %stream.
 */
#ifndef COMMK_EXTRAFIELDS
#define COMMK_EXTRAFIELDS 3
#endif

/**
 * @brief Flag indicating that the %stream has been transmitted.
 */
#define TX_STREAM_OK 0
#include <stdint.h>


/**
 * @brief Structure for defining the %stream data.
 * 
 * It comprises a data array field and a command field.
 */
typedef struct{
	unsigned char command;
	char data[COMMK_DATASIZE];
}stream;


/**
 * @brief Initialization of communiication hardware.
 * 
 * Initializes the uart hardware, by using the @ref nxbot_uart module.
 *
 * @param baudrate Calculated using the UART_BAUD_SELECT() function.
 * @param format One of the UART_FORMAT_ constants.
 * @param usart Uart hardware to be used (0 or 1).
 *
 * @see @ref nxbot_uart
 */
void comm_init(unsigned int baudrate, unsigned char format, unsigned char usart);

/**
 * @brief Transmit a stream via the selected uart.
 * 
 * @param txStream The stream to be sended.
 * @param usart Uart module to be used for the transmission.
 */
unsigned char comm_transmit(stream *txStream,uint8_t usart);


/**
 * @brief Receive a stream via the selected uart.
 * 
 * @param rxStream The received stream.
 * @param usart Uart module to be used for the reception.
 */
unsigned char comm_receive(stream *rxStream,uint8_t usart);

/**@}*/
#endif
